package jh.com.jhappbf.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class SettingModel implements Parcelable {
    private String startDateTime;
    private String endDateTime;
    private String cargoname;
    private String platenumber;
    private String sender;
    private String receiver;
    private String sitePoint;

    /**
     * 开始日期时间
     *
     * @return
     */
    public String getStartDateTime() {
        if (TextUtils.isEmpty(startDateTime)) {
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
            return format.format(calendar.getTime()) + " 00:00:00";
        } else {
            return startDateTime;
        }
    }

    public void setStartDateTime(String startDateTime) {
        this.startDateTime = startDateTime;
    }


    /**
     * 结束日期时间
     *
     * @return
     */
    public String getEndDateTime() {

        if (TextUtils.isEmpty(endDateTime)) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
            return format.format(new Date()) + " 23:59:59";
        } else {
            return endDateTime;
        }
    }

    public void setEndDateTime(String endDateTime) {
        this.endDateTime = endDateTime;
    }

    /**
     * 货名
     *
     * @return
     */
    public String getCargoname() {
        if (TextUtils.isEmpty(cargoname)) {
            return "";
        } else {
            return cargoname;
        }
    }

    public void setCargoname(String cargoname) {
        this.cargoname = cargoname;
    }

    /**
     * 车号
     *
     * @return
     */
    public String getPlatenumber() {
        if (TextUtils.isEmpty(platenumber)) {
            return "";
        } else {
            return platenumber;
        }
    }

    public void setPlatenumber(String platenumber) {
        this.platenumber = platenumber;
    }


    public String getSender() {
        if (TextUtils.isEmpty(sender)) {
            return "";
        } else {
            return sender;
        }
    }

    public void setSender(String sender) {
        this.sender = sender;
    }

    public String getReceiver() {
        if (TextUtils.isEmpty(receiver)) {
            return "";
        } else {
            return receiver;
        }
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    public String getSitePoint() {
        if (TextUtils.isEmpty(sitePoint)) {
            return "";
        } else {
            return sitePoint;
        }
    }

    public void setSitePoint(String sitePoint) {
        this.sitePoint = sitePoint;
    }

    public SettingModel() {

    }

    private SettingModel(Parcel source) {
        startDateTime = source.readString();
        endDateTime = source.readString();
        cargoname = source.readString();
        platenumber = source.readString();
        sender = source.readString();
        receiver = source.readString();
        sitePoint = source.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(startDateTime);
        dest.writeString(endDateTime);
        dest.writeString(cargoname);
        dest.writeString(platenumber);
        dest.writeString(sender);
        dest.writeString(receiver);
        dest.writeString(sitePoint);
    }

    public static final Creator<SettingModel> CREATOR = new Creator<SettingModel>() {

        @Override
        public SettingModel createFromParcel(Parcel source) {
            return new SettingModel(source);
        }

        @Override
        public SettingModel[] newArray(int size) {
            return new SettingModel[size];
        }
    };
}
